
function hexChar( num ){
    var chars = '0123456789ABCDEF';
    return chars.charAt( num );
}

function strToHex( str ){
    var encoded = "";
    for( var i = 0 ; i < str.length ; i++ ){
        var code = str.charCodeAt( i );
        if( code <= 255 ){
            b1 = (code >>> 4 )& 0xF;;
            b2 = code & 0xF;
            encoded += "_" + hexChar( b1 ) + hexChar( b2 );
        }
        else{
            b1 = (code >>> 12)& 0xF;
            b2 = (code >>> 8 )& 0xF;
            b3 = (code >>> 4 )& 0xF;
            b4 = (code) & 0xF;
            encoded += "_u" + hexChar( b1 ) + hexChar( b2 ) + hexChar( b3 ) + hexChar( b4 );
        }
    }
    return encoded;
}

function getSelectedValue( ids ){
    var items = new Array();
    if( null == ids.length ){
        items.push( ids.value );
    }
    else{
        for( var i = 0 ; i < ids.length ; i++ ){
            if( ids[i].checked ){
                items.push( ids[i].value );
            }
        }
    }
    return items;
}

function selectRadio( radios , value ){
	if( radios.length == null ){
		radios.click();
	}
	else{
		var checked = false;
		for( var i = 0 ; i < radios.length ; i++ ){
			radio = radios[i];
			if( radio.value == value ){
				checked = true;
				radio.checked = checked;
				break;
			}
		}
		
		if( checked == false ){
			radios[0].checked = true;
		}
	}
}

function selectValue( select , value ){
	var options = select.options;
	for( i = 0 ; i < options.length ; i++ ){
		var op = options[i];
		if( op.value == value ){
			select.selectedIndex = i;
			break;
		}
	}
}


function contains( array , str ){
    for( var i = 0 ; i < array.length ; i++ ){
        if( array[i] == str ){
            return true;
        }
    }
    return false;
}

function initSelect( select , value ){
	var options = select.options;
	for( i = 0 ; i < options.length ; i++ ){
		var op = options[i];
		if( op.value == value ){
			select.selectedIndex = i;
			break;
		}
	}
}
